package net.peelmeagrape.hibernate;

import net.peelmeagrape.hibernate.xmlgen.XmlAttribute;
import net.peelmeagrape.hibernate.xmlgen.XmlElement;
import net.peelmeagrape.hibernate.xmlgen.XmlText;

import static java.lang.annotation.ElementType.*;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;

/**
 * If you use a certain UserType very often, it may be useful to define a shorter name for it. You can do this using
 * the {@link TypeDef} element. Typedefs assign a name to a custom type, and may also contain a list of default
 * parameter values if the type is parameterized.
 * See <a href="{@docRoot}/reference/en/html/mapping.html#mapping-types-custom">Hibernate Documentation for custom value types</a>.

 */
@Target({METHOD,FIELD,CONSTRUCTOR,TYPE,PACKAGE})
@Retention(RUNTIME)
@XmlElement(name="typedef", parent="hibernate-mapping")
public @interface TypeDef
{
    @XmlAttribute("class") Class clazz();
    @XmlAttribute String name();
    Param[] params() default {};

    /**
     * Default values for a custom value type.
     */
    @XmlElement(name="param")
    public @interface Param {
        @XmlAttribute String name();
        @XmlText String value();
    }
}
